package com.cskaoyan.eighth.service;

import com.cskaoyan.eighth.bean.BaseListData;
import com.cskaoyan.eighth.bean.User;
import com.cskaoyan.eighth.bean.UserExample;
import com.cskaoyan.eighth.mapper.UserMapper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public BaseListData queryUsers(Integer page, Integer limit, String sort, String order) {
        PageHelper.startPage(page,limit);
        UserExample userExample = new UserExample();
        userExample.setOrderByClause(sort + " " + order);
        List<User> users = userMapper.selectByExample(userExample);
        //total不是users的size，而是满足条件（不包括）的全部的数据量
        PageInfo<User> pageInfo = new PageInfo<User>(users);
        long total = pageInfo.getTotal();

        return BaseListData.ok(users,total);
    }
}
